package com.day0923.shopping.manager;

import com.day0923.shopping.data.Date;
import com.day0923.shopping.data.Manager;

import java.util.Scanner;

public class StartMES {
//    public boolean loginThree(Date date){
//
//    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        Date date = new Date();
        date.getManagers();
        date.getGoods();
        date.getCustomers();
        Menu menu = new Menu();
        menu.custManager.date = date;
        menu.custManager.menu = menu;
        menu.purchaseSettlement.date = date;
        menu.purchaseSettlement.menu = menu;
        menu.showLoginMenus();
        int choose = in.nextInt();//switch选择条件
        int cho = 0;//循环条件
        String username;
        String userpwd;
        do {
            switch (choose){
                case 1:
                    int count = 3;
                    do {
                        count--;
                        System.out.print("请输入用户名：");
                        username = in.next();
                        System.out.print("请输入密码：");
                        userpwd = in.next();
                        if (date.login(username,userpwd) != null){
                            System.out.println("登陆成功！");
                            menu.showMainMenus();
                            return;
                        }
                        else {
                            System.out.println("登录失败!");
                            System.out.println("你还有" + count + "次机会");
                        }
                    }while (count > 0);
                    if (count == 0){
                        System.exit(0);
                    }
                    break;
                case 2:
                    System.out.print("请输入用户名：");
                    username = in.next();
                    System.out.print("请输入密码：");
                    userpwd = in.next();
                    Manager current = date.login(username,userpwd);
                    if (current != null){
                        System.out.print("请输入新的用户名：");
                        String newusername = in.next();
                        System.out.print("请输入新的密码：");
                        String newuserpwd = in.next();
                        current.setUsername(newusername);
                        current.setUserpwd(newuserpwd);
                        System.out.println("账号密码更改成功！");
                    }
                    else {
                        System.out.println("无权限!");
                    }
                    System.out.println("请选择输入数字：");
                    cho = in.nextInt();
                    break;
                case 3:
                    System.exit(0);
                    break;
                default:
                    System.out.println("请输入1-3：");
                    choose = in.nextInt();
                    break;
            }
        }while (cho != 3);

    }
}
